import React, { Component } from 'react'
import { Select } from 'antd'
import { getChannels } from 'api/channels'

export class Channel extends Component {
    state = {
        channelslist:[]
    }
    render() {
        return (
        <div>
            <Select value={this.props.value} onChange={this.props.onChange} style={{ width: 200 }} placeholder='请选择频道'>
                {this.state.channelslist.map((item) => <Select.Option key={item.id} value={item.id}>{item.name}</Select.Option> )}
            </Select>
        </div>
        )
    }
    componentDidMount() {
        this.getChannelsList()
    }
    async getChannelsList() { //获取频道列表数据
        const clres = await getChannels()
        this.setState({
          channelslist:clres.data.channels
        })
    }
}

export default Channel